<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>modulemanager.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_module_modulemanager.js.html">modulemanager.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A singleton object for managing Javascript code modules.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.module.ModuleManager&#39;);
<a name="line21"></a>goog.provide(&#39;goog.module.ModuleManager.CallbackType&#39;);
<a name="line22"></a>goog.provide(&#39;goog.module.ModuleManager.FailureType&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.Disposable&#39;);
<a name="line25"></a>goog.require(&#39;goog.array&#39;);
<a name="line26"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line27"></a>goog.require(&#39;goog.async.Deferred&#39;);
<a name="line28"></a>goog.require(&#39;goog.debug.Trace&#39;);
<a name="line29"></a>/** @suppress {extraRequire} */
<a name="line30"></a>goog.require(&#39;goog.dispose&#39;);
<a name="line31"></a>goog.require(&#39;goog.log&#39;);
<a name="line32"></a>goog.require(&#39;goog.module.ModuleInfo&#39;);
<a name="line33"></a>goog.require(&#39;goog.module.ModuleLoadCallback&#39;);
<a name="line34"></a>goog.require(&#39;goog.object&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * The ModuleManager keeps track of all modules in the environment.
<a name="line40"></a> * Since modules may not have their code loaded, we must keep track of them.
<a name="line41"></a> * @constructor
<a name="line42"></a> * @extends {goog.Disposable}
<a name="line43"></a> */
<a name="line44"></a>goog.module.ModuleManager = function() {
<a name="line45"></a>  goog.Disposable.call(this);
<a name="line46"></a>
<a name="line47"></a>  /**
<a name="line48"></a>   * A mapping from module id to ModuleInfo object.
<a name="line49"></a>   * @type {Object}
<a name="line50"></a>   * @private
<a name="line51"></a>   */
<a name="line52"></a>  this.moduleInfoMap_ = {};
<a name="line53"></a>
<a name="line54"></a>  // TODO (malteubl): Switch this to a reentrant design.
<a name="line55"></a>  /**
<a name="line56"></a>   * The ids of the currently loading modules. If batch mode is disabled, then
<a name="line57"></a>   * this array will never contain more than one element at a time.
<a name="line58"></a>   * @type {Array.&lt;string&gt;}
<a name="line59"></a>   * @private
<a name="line60"></a>   */
<a name="line61"></a>  this.loadingModuleIds_ = [];
<a name="line62"></a>
<a name="line63"></a>  /**
<a name="line64"></a>   * The requested ids of the currently loading modules. This does not include
<a name="line65"></a>   * module dependencies that may also be loading.
<a name="line66"></a>   * @type {Array.&lt;string&gt;}
<a name="line67"></a>   * @private
<a name="line68"></a>   */
<a name="line69"></a>  this.requestedLoadingModuleIds_ = [];
<a name="line70"></a>
<a name="line71"></a>  // TODO(user): Make these and other arrays that are used as sets be
<a name="line72"></a>  // actual sets.
<a name="line73"></a>  /**
<a name="line74"></a>   * All module ids that have ever been requested. In concurrent loading these
<a name="line75"></a>   * are the ones to subtract from future requests.
<a name="line76"></a>   * @type {!Array.&lt;string&gt;}
<a name="line77"></a>   * @private
<a name="line78"></a>   */
<a name="line79"></a>  this.requestedModuleIds_ = [];
<a name="line80"></a>
<a name="line81"></a>  /**
<a name="line82"></a>   * A queue of the ids of requested but not-yet-loaded modules. The zero
<a name="line83"></a>   * position is the front of the queue. This is a 2-D array to group modules
<a name="line84"></a>   * together with other modules that should be batch loaded with them, if
<a name="line85"></a>   * batch loading is enabled.
<a name="line86"></a>   * @type {Array.&lt;Array.&lt;string&gt;&gt;}
<a name="line87"></a>   * @private
<a name="line88"></a>   */
<a name="line89"></a>  this.requestedModuleIdsQueue_ = [];
<a name="line90"></a>
<a name="line91"></a>  /**
<a name="line92"></a>   * The ids of the currently loading modules which have been initiated by user
<a name="line93"></a>   * actions.
<a name="line94"></a>   * @type {Array.&lt;string&gt;}
<a name="line95"></a>   * @private
<a name="line96"></a>   */
<a name="line97"></a>  this.userInitiatedLoadingModuleIds_ = [];
<a name="line98"></a>
<a name="line99"></a>  /**
<a name="line100"></a>   * A map of callback types to the functions to call for the specified
<a name="line101"></a>   * callback type.
<a name="line102"></a>   * @type {Object}
<a name="line103"></a>   * @private
<a name="line104"></a>   */
<a name="line105"></a>  this.callbackMap_ = {};
<a name="line106"></a>
<a name="line107"></a>  /**
<a name="line108"></a>   * Module info for the base module (the one that contains the module
<a name="line109"></a>   * manager code), which we set as the loading module so one can
<a name="line110"></a>   * register initialization callbacks in the base module.
<a name="line111"></a>   *
<a name="line112"></a>   * The base module is considered loaded when #setAllModuleInfo is called or
<a name="line113"></a>   * #setModuleContext is called, whichever comes first.
<a name="line114"></a>   *
<a name="line115"></a>   * @type {goog.module.ModuleInfo}
<a name="line116"></a>   * @private
<a name="line117"></a>   */
<a name="line118"></a>  this.baseModuleInfo_ = new goog.module.ModuleInfo([], &#39;&#39;);
<a name="line119"></a>
<a name="line120"></a>  /**
<a name="line121"></a>   * The module that is currently loading, or null if not loading anything.
<a name="line122"></a>   * @type {goog.module.ModuleInfo}
<a name="line123"></a>   * @private
<a name="line124"></a>   */
<a name="line125"></a>  this.currentlyLoadingModule_ = this.baseModuleInfo_;
<a name="line126"></a>
<a name="line127"></a>  /**
<a name="line128"></a>   * The id of the last requested initial module. When it loaded
<a name="line129"></a>   * the deferred in {@code this.initialModulesLoaded_} resolves.
<a name="line130"></a>   * @private {?string}
<a name="line131"></a>   */
<a name="line132"></a>  this.lastInitialModuleId_ = null;
<a name="line133"></a>
<a name="line134"></a>  /**
<a name="line135"></a>   * Deferred for when all initial modules have loaded. We currently block
<a name="line136"></a>   * sending additional module requests until this deferred resolves. In a
<a name="line137"></a>   * future optimization it may be possible to use the initial modules as
<a name="line138"></a>   * seeds for the module loader &quot;requested module ids&quot; and start making new
<a name="line139"></a>   * requests even sooner.
<a name="line140"></a>   * @private {!goog.async.Deferred}
<a name="line141"></a>   */
<a name="line142"></a>  this.initialModulesLoaded_ = new goog.async.Deferred();
<a name="line143"></a>};
<a name="line144"></a>goog.inherits(goog.module.ModuleManager, goog.Disposable);
<a name="line145"></a>goog.addSingletonGetter(goog.module.ModuleManager);
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>/**
<a name="line149"></a>* The type of callbacks that can be registered with the module manager,.
<a name="line150"></a>* @enum {string}
<a name="line151"></a>*/
<a name="line152"></a>goog.module.ModuleManager.CallbackType = {
<a name="line153"></a>  /**
<a name="line154"></a>   * Fired when an error has occurred.
<a name="line155"></a>   */
<a name="line156"></a>  ERROR: &#39;error&#39;,
<a name="line157"></a>
<a name="line158"></a>  /**
<a name="line159"></a>   * Fired when it becomes idle and has no more module loads to process.
<a name="line160"></a>   */
<a name="line161"></a>  IDLE: &#39;idle&#39;,
<a name="line162"></a>
<a name="line163"></a>  /**
<a name="line164"></a>   * Fired when it becomes active and has module loads to process.
<a name="line165"></a>   */
<a name="line166"></a>  ACTIVE: &#39;active&#39;,
<a name="line167"></a>
<a name="line168"></a>  /**
<a name="line169"></a>   * Fired when it becomes idle and has no more user-initiated module loads to
<a name="line170"></a>   * process.
<a name="line171"></a>   */
<a name="line172"></a>  USER_IDLE: &#39;userIdle&#39;,
<a name="line173"></a>
<a name="line174"></a>  /**
<a name="line175"></a>   * Fired when it becomes active and has user-initiated module loads to
<a name="line176"></a>   * process.
<a name="line177"></a>   */
<a name="line178"></a>  USER_ACTIVE: &#39;userActive&#39;
<a name="line179"></a>};
<a name="line180"></a>
<a name="line181"></a>
<a name="line182"></a>/**
<a name="line183"></a> * A non-HTTP status code indicating a corruption in loaded module.
<a name="line184"></a> * This should be used by a ModuleLoader as a replacement for the HTTP code
<a name="line185"></a> * given to the error handler function to indicated that the module was
<a name="line186"></a> * corrupted.
<a name="line187"></a> * This will set the forceReload flag on the loadModules method when retrying
<a name="line188"></a> * module loading.
<a name="line189"></a> * @type {number}
<a name="line190"></a> */
<a name="line191"></a>goog.module.ModuleManager.CORRUPT_RESPONSE_STATUS_CODE = 8001;
<a name="line192"></a>
<a name="line193"></a>
<a name="line194"></a>/**
<a name="line195"></a> * A logger.
<a name="line196"></a> * @type {goog.log.Logger}
<a name="line197"></a> * @private
<a name="line198"></a> */
<a name="line199"></a>goog.module.ModuleManager.prototype.logger_ = goog.log.getLogger(
<a name="line200"></a>    &#39;goog.module.ModuleManager&#39;);
<a name="line201"></a>
<a name="line202"></a>
<a name="line203"></a>/**
<a name="line204"></a> * Whether the batch mode (i.e. the loading of multiple modules with just one
<a name="line205"></a> * request) has been enabled.
<a name="line206"></a> * @type {boolean}
<a name="line207"></a> * @private
<a name="line208"></a> */
<a name="line209"></a>goog.module.ModuleManager.prototype.batchModeEnabled_ = false;
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * Whether the module requests may be sent out of order.
<a name="line214"></a> * @type {boolean}
<a name="line215"></a> * @private
<a name="line216"></a> */
<a name="line217"></a>goog.module.ModuleManager.prototype.concurrentLoadingEnabled_ = false;
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * A loader for the modules that implements loadModules(ids, moduleInfoMap,
<a name="line222"></a> * opt_successFn, opt_errorFn, opt_timeoutFn, opt_forceReload) method.
<a name="line223"></a> * @type {goog.module.AbstractModuleLoader}
<a name="line224"></a> * @private
<a name="line225"></a> */
<a name="line226"></a>goog.module.ModuleManager.prototype.loader_ = null;
<a name="line227"></a>
<a name="line228"></a>
<a name="line229"></a>// TODO(user): Remove tracer.
<a name="line230"></a>/**
<a name="line231"></a> * Tracer that measures how long it takes to load a module.
<a name="line232"></a> * @type {?number}
<a name="line233"></a> * @private
<a name="line234"></a> */
<a name="line235"></a>goog.module.ModuleManager.prototype.loadTracer_ = null;
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/**
<a name="line239"></a> * The number of consecutive failures that have happened upon module load
<a name="line240"></a> * requests.
<a name="line241"></a> * @type {number}
<a name="line242"></a> * @private
<a name="line243"></a> */
<a name="line244"></a>goog.module.ModuleManager.prototype.consecutiveFailures_ = 0;
<a name="line245"></a>
<a name="line246"></a>
<a name="line247"></a>/**
<a name="line248"></a> * Determines if the module manager was just active before the processing of
<a name="line249"></a> * the last data.
<a name="line250"></a> * @type {boolean}
<a name="line251"></a> * @private
<a name="line252"></a> */
<a name="line253"></a>goog.module.ModuleManager.prototype.lastActive_ = false;
<a name="line254"></a>
<a name="line255"></a>
<a name="line256"></a>/**
<a name="line257"></a> * Determines if the module manager was just user active before the processing
<a name="line258"></a> * of the last data. The module manager is user active if any of the
<a name="line259"></a> * user-initiated modules are loading or queued up to load.
<a name="line260"></a> * @type {boolean}
<a name="line261"></a> * @private
<a name="line262"></a> */
<a name="line263"></a>goog.module.ModuleManager.prototype.userLastActive_ = false;
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * The module context needed for module initialization.
<a name="line268"></a> * @type {Object}
<a name="line269"></a> * @private
<a name="line270"></a> */
<a name="line271"></a>goog.module.ModuleManager.prototype.moduleContext_ = null;
<a name="line272"></a>
<a name="line273"></a>
<a name="line274"></a>/**
<a name="line275"></a> * Sets the batch mode as enabled or disabled for the module manager.
<a name="line276"></a> * @param {boolean} enabled Whether the batch mode is to be enabled or not.
<a name="line277"></a> */
<a name="line278"></a>goog.module.ModuleManager.prototype.setBatchModeEnabled = function(
<a name="line279"></a>    enabled) {
<a name="line280"></a>  this.batchModeEnabled_ = enabled;
<a name="line281"></a>};
<a name="line282"></a>
<a name="line283"></a>
<a name="line284"></a>/**
<a name="line285"></a> * Sets the concurrent loading mode as enabled or disabled for the module
<a name="line286"></a> * manager. Requires a moduleloader implementation that supports concurrent
<a name="line287"></a> * loads. The default {@see goog.module.ModuleLoader} does not.
<a name="line288"></a> * @param {boolean} enabled
<a name="line289"></a> */
<a name="line290"></a>goog.module.ModuleManager.prototype.setConcurrentLoadingEnabled = function(
<a name="line291"></a>    enabled) {
<a name="line292"></a>  this.concurrentLoadingEnabled_ = enabled;
<a name="line293"></a>};
<a name="line294"></a>
<a name="line295"></a>
<a name="line296"></a>/**
<a name="line297"></a> * Sets the module info for all modules. Should only be called once.
<a name="line298"></a> *
<a name="line299"></a> * @param {Object.&lt;Array.&lt;string&gt;&gt;} infoMap An object that contains a mapping
<a name="line300"></a> *    from module id (String) to list of required module ids (Array).
<a name="line301"></a> */
<a name="line302"></a>goog.module.ModuleManager.prototype.setAllModuleInfo = function(infoMap) {
<a name="line303"></a>  for (var id in infoMap) {
<a name="line304"></a>    this.moduleInfoMap_[id] = new goog.module.ModuleInfo(infoMap[id], id);
<a name="line305"></a>  }
<a name="line306"></a>  if (!this.initialModulesLoaded_.hasFired()) {
<a name="line307"></a>    this.initialModulesLoaded_.callback();
<a name="line308"></a>  }
<a name="line309"></a>  this.maybeFinishBaseLoad_();
<a name="line310"></a>};
<a name="line311"></a>
<a name="line312"></a>
<a name="line313"></a>/**
<a name="line314"></a> * Sets the module info for all modules. Should only be called once. Also
<a name="line315"></a> * marks modules that are currently being loaded.
<a name="line316"></a> *
<a name="line317"></a> * @param {string=} opt_info A string representation of the module dependency
<a name="line318"></a> *      graph, in the form: module1:dep1,dep2/module2:dep1,dep2 etc.
<a name="line319"></a> *     Where depX is the base-36 encoded position of the dep in the module list.
<a name="line320"></a> * @param {Array.&lt;string&gt;=} opt_loadingModuleIds A list of moduleIds that
<a name="line321"></a> *     are currently being loaded.
<a name="line322"></a> */
<a name="line323"></a>goog.module.ModuleManager.prototype.setAllModuleInfoString = function(
<a name="line324"></a>    opt_info, opt_loadingModuleIds) {
<a name="line325"></a>  if (!goog.isString(opt_info)) {
<a name="line326"></a>    // The call to this method is generated in two steps, the argument is added
<a name="line327"></a>    // after some of the compilation passes.  This means that the initial code
<a name="line328"></a>    // doesn&#39;t have any arguments and causes compiler errors.  We make it
<a name="line329"></a>    // optional to satisfy this constraint.
<a name="line330"></a>    return;
<a name="line331"></a>  }
<a name="line332"></a>
<a name="line333"></a>  var modules = opt_info.split(&#39;/&#39;);
<a name="line334"></a>  var moduleIds = [];
<a name="line335"></a>
<a name="line336"></a>  // Split the string into the infoMap of id-&gt;deps
<a name="line337"></a>  for (var i = 0; i &lt; modules.length; i++) {
<a name="line338"></a>    var parts = modules[i].split(&#39;:&#39;);
<a name="line339"></a>    var id = parts[0];
<a name="line340"></a>    var deps;
<a name="line341"></a>    if (parts[1]) {
<a name="line342"></a>      deps = parts[1].split(&#39;,&#39;);
<a name="line343"></a>      for (var j = 0; j &lt; deps.length; j++) {
<a name="line344"></a>        var index = parseInt(deps[j], 36);
<a name="line345"></a>        goog.asserts.assert(
<a name="line346"></a>            moduleIds[index], &#39;No module @ %s, dep of %s @ %s&#39;, index, id, i);
<a name="line347"></a>        deps[j] = moduleIds[index];
<a name="line348"></a>      }
<a name="line349"></a>    } else {
<a name="line350"></a>      deps = [];
<a name="line351"></a>    }
<a name="line352"></a>    moduleIds.push(id);
<a name="line353"></a>    this.moduleInfoMap_[id] = new goog.module.ModuleInfo(deps, id);
<a name="line354"></a>  }
<a name="line355"></a>  if (opt_loadingModuleIds &amp;&amp; opt_loadingModuleIds.length) {
<a name="line356"></a>    goog.array.extend(this.loadingModuleIds_, opt_loadingModuleIds);
<a name="line357"></a>    // The last module in the list of initial modules. When it has loaded all
<a name="line358"></a>    // initial modules have loaded.
<a name="line359"></a>    this.lastInitialModuleId_ = /** @type {?string}  */ (
<a name="line360"></a>        goog.array.peek(opt_loadingModuleIds));
<a name="line361"></a>  } else {
<a name="line362"></a>    if (!this.initialModulesLoaded_.hasFired()) {
<a name="line363"></a>      this.initialModulesLoaded_.callback();
<a name="line364"></a>    }
<a name="line365"></a>  }
<a name="line366"></a>  this.maybeFinishBaseLoad_();
<a name="line367"></a>};
<a name="line368"></a>
<a name="line369"></a>
<a name="line370"></a>/**
<a name="line371"></a> * Gets a module info object by id.
<a name="line372"></a> * @param {string} id A module identifier.
<a name="line373"></a> * @return {goog.module.ModuleInfo} The module info.
<a name="line374"></a> */
<a name="line375"></a>goog.module.ModuleManager.prototype.getModuleInfo = function(id) {
<a name="line376"></a>  return this.moduleInfoMap_[id];
<a name="line377"></a>};
<a name="line378"></a>
<a name="line379"></a>
<a name="line380"></a>/**
<a name="line381"></a> * Sets the module uris.
<a name="line382"></a> *
<a name="line383"></a> * @param {Object} moduleUriMap The map of id/uris pairs for each module.
<a name="line384"></a> */
<a name="line385"></a>goog.module.ModuleManager.prototype.setModuleUris = function(moduleUriMap) {
<a name="line386"></a>  for (var id in moduleUriMap) {
<a name="line387"></a>    this.moduleInfoMap_[id].setUris(moduleUriMap[id]);
<a name="line388"></a>  }
<a name="line389"></a>};
<a name="line390"></a>
<a name="line391"></a>
<a name="line392"></a>/**
<a name="line393"></a> * Gets the application-specific module loader.
<a name="line394"></a> * @return {goog.module.AbstractModuleLoader} An object that has a
<a name="line395"></a> *     loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn,
<a name="line396"></a> *         opt_timeoutFn, opt_forceReload) method.
<a name="line397"></a> */
<a name="line398"></a>goog.module.ModuleManager.prototype.getLoader = function() {
<a name="line399"></a>  return this.loader_;
<a name="line400"></a>};
<a name="line401"></a>
<a name="line402"></a>
<a name="line403"></a>/**
<a name="line404"></a> * Sets the application-specific module loader.
<a name="line405"></a> * @param {goog.module.AbstractModuleLoader} loader An object that has a
<a name="line406"></a> *     loadModules(ids, moduleInfoMap, opt_successFn, opt_errFn,
<a name="line407"></a> *         opt_timeoutFn, opt_forceReload) method.
<a name="line408"></a> */
<a name="line409"></a>goog.module.ModuleManager.prototype.setLoader = function(loader) {
<a name="line410"></a>  this.loader_ = loader;
<a name="line411"></a>};
<a name="line412"></a>
<a name="line413"></a>
<a name="line414"></a>/**
<a name="line415"></a> * Gets the module context to use to initialize the module.
<a name="line416"></a> * @return {Object} The context.
<a name="line417"></a> */
<a name="line418"></a>goog.module.ModuleManager.prototype.getModuleContext = function() {
<a name="line419"></a>  return this.moduleContext_;
<a name="line420"></a>};
<a name="line421"></a>
<a name="line422"></a>
<a name="line423"></a>/**
<a name="line424"></a> * Sets the module context to use to initialize the module.
<a name="line425"></a> * @param {Object} context The context.
<a name="line426"></a> */
<a name="line427"></a>goog.module.ModuleManager.prototype.setModuleContext = function(context) {
<a name="line428"></a>  this.moduleContext_ = context;
<a name="line429"></a>  this.maybeFinishBaseLoad_();
<a name="line430"></a>};
<a name="line431"></a>
<a name="line432"></a>
<a name="line433"></a>/**
<a name="line434"></a> * Determines if the ModuleManager is active
<a name="line435"></a> * @return {boolean} TRUE iff the ModuleManager is active (i.e., not idle).
<a name="line436"></a> */
<a name="line437"></a>goog.module.ModuleManager.prototype.isActive = function() {
<a name="line438"></a>  return this.loadingModuleIds_.length &gt; 0;
<a name="line439"></a>};
<a name="line440"></a>
<a name="line441"></a>
<a name="line442"></a>/**
<a name="line443"></a> * Determines if the ModuleManager is user active
<a name="line444"></a> * @return {boolean} TRUE iff the ModuleManager is user active (i.e., not idle).
<a name="line445"></a> */
<a name="line446"></a>goog.module.ModuleManager.prototype.isUserActive = function() {
<a name="line447"></a>  return this.userInitiatedLoadingModuleIds_.length &gt; 0;
<a name="line448"></a>};
<a name="line449"></a>
<a name="line450"></a>
<a name="line451"></a>/**
<a name="line452"></a> * Dispatches an ACTIVE or IDLE event if necessary.
<a name="line453"></a> * @private
<a name="line454"></a> */
<a name="line455"></a>goog.module.ModuleManager.prototype.dispatchActiveIdleChangeIfNeeded_ =
<a name="line456"></a>    function() {
<a name="line457"></a>  var lastActive = this.lastActive_;
<a name="line458"></a>  var active = this.isActive();
<a name="line459"></a>  if (active != lastActive) {
<a name="line460"></a>    this.executeCallbacks_(active ?
<a name="line461"></a>        goog.module.ModuleManager.CallbackType.ACTIVE :
<a name="line462"></a>        goog.module.ModuleManager.CallbackType.IDLE);
<a name="line463"></a>
<a name="line464"></a>    // Flip the last active value.
<a name="line465"></a>    this.lastActive_ = active;
<a name="line466"></a>  }
<a name="line467"></a>
<a name="line468"></a>  // Check if the module manager is user active i.e., there are user initiated
<a name="line469"></a>  // modules being loaded or queued up to be loaded.
<a name="line470"></a>  var userLastActive = this.userLastActive_;
<a name="line471"></a>  var userActive = this.isUserActive();
<a name="line472"></a>  if (userActive != userLastActive) {
<a name="line473"></a>    this.executeCallbacks_(userActive ?
<a name="line474"></a>        goog.module.ModuleManager.CallbackType.USER_ACTIVE :
<a name="line475"></a>        goog.module.ModuleManager.CallbackType.USER_IDLE);
<a name="line476"></a>
<a name="line477"></a>    // Flip the last user active value.
<a name="line478"></a>    this.userLastActive_ = userActive;
<a name="line479"></a>  }
<a name="line480"></a>};
<a name="line481"></a>
<a name="line482"></a>
<a name="line483"></a>/**
<a name="line484"></a> * Preloads a module after a short delay.
<a name="line485"></a> *
<a name="line486"></a> * @param {string} id The id of the module to preload.
<a name="line487"></a> * @param {number=} opt_timeout The number of ms to wait before adding the
<a name="line488"></a> *     module id to the loading queue (defaults to 0 ms). Note that the module
<a name="line489"></a> *     will be loaded asynchronously regardless of the value of this parameter.
<a name="line490"></a> * @return {!goog.async.Deferred} A deferred object.
<a name="line491"></a> */
<a name="line492"></a>goog.module.ModuleManager.prototype.preloadModule = function(
<a name="line493"></a>    id, opt_timeout) {
<a name="line494"></a>  var d = new goog.async.Deferred();
<a name="line495"></a>  window.setTimeout(
<a name="line496"></a>      goog.bind(this.addLoadModule_, this, id, d),
<a name="line497"></a>      opt_timeout || 0);
<a name="line498"></a>  return d;
<a name="line499"></a>};
<a name="line500"></a>
<a name="line501"></a>
<a name="line502"></a>/**
<a name="line503"></a> * Prefetches a JavaScript module and its dependencies, which means that the
<a name="line504"></a> * module will be downloaded, but not evaluated. To complete the module load,
<a name="line505"></a> * the caller should also call load or execOnLoad after prefetching the module.
<a name="line506"></a> *
<a name="line507"></a> * @param {string} id The id of the module to prefetch.
<a name="line508"></a> */
<a name="line509"></a>goog.module.ModuleManager.prototype.prefetchModule = function(id) {
<a name="line510"></a>  var moduleInfo = this.getModuleInfo(id);
<a name="line511"></a>  if (moduleInfo.isLoaded() || this.isModuleLoading(id)) {
<a name="line512"></a>    throw Error(&#39;Module load already requested: &#39; + id);
<a name="line513"></a>  } else if (this.batchModeEnabled_) {
<a name="line514"></a>    throw Error(&#39;Modules prefetching is not supported in batch mode&#39;);
<a name="line515"></a>  } else {
<a name="line516"></a>    var idWithDeps = this.getNotYetLoadedTransitiveDepIds_(id);
<a name="line517"></a>    for (var i = 0; i &lt; idWithDeps.length; i++) {
<a name="line518"></a>      this.loader_.prefetchModule(idWithDeps[i],
<a name="line519"></a>          this.moduleInfoMap_[idWithDeps[i]]);
<a name="line520"></a>    }
<a name="line521"></a>  }
<a name="line522"></a>};
<a name="line523"></a>
<a name="line524"></a>
<a name="line525"></a>/**
<a name="line526"></a> * Loads a single module for use with a given deferred.
<a name="line527"></a> *
<a name="line528"></a> * @param {string} id The id of the module to load.
<a name="line529"></a> * @param {goog.async.Deferred} d A deferred object.
<a name="line530"></a> * @private
<a name="line531"></a> */
<a name="line532"></a>goog.module.ModuleManager.prototype.addLoadModule_ = function(id, d) {
<a name="line533"></a>  var moduleInfo = this.getModuleInfo(id);
<a name="line534"></a>  if (moduleInfo.isLoaded()) {
<a name="line535"></a>    d.callback(this.moduleContext_);
<a name="line536"></a>    return;
<a name="line537"></a>  }
<a name="line538"></a>
<a name="line539"></a>  this.registerModuleLoadCallbacks_(id, moduleInfo, false, d);
<a name="line540"></a>  if (!this.isModuleLoading(id)) {
<a name="line541"></a>    this.loadModulesOrEnqueue_([id]);
<a name="line542"></a>  }
<a name="line543"></a>};
<a name="line544"></a>
<a name="line545"></a>
<a name="line546"></a>/**
<a name="line547"></a> * Loads a list of modules or, if some other module is currently being loaded,
<a name="line548"></a> * appends the ids to the queue of requested module ids. Registers callbacks a
<a name="line549"></a> * module that is currently loading and returns a fired deferred for a module
<a name="line550"></a> * that is already loaded.
<a name="line551"></a> *
<a name="line552"></a> * @param {Array.&lt;string&gt;} ids The id of the module to load.
<a name="line553"></a> * @param {boolean=} opt_userInitiated If the load is a result of a user action.
<a name="line554"></a> * @return {!Object.&lt;!goog.async.Deferred&gt;} A mapping from id (String) to
<a name="line555"></a> *     deferred objects that will callback or errback when the load for that
<a name="line556"></a> *     id is finished.
<a name="line557"></a> * @private
<a name="line558"></a> */
<a name="line559"></a>goog.module.ModuleManager.prototype.loadModulesOrEnqueueIfNotLoadedOrLoading_ =
<a name="line560"></a>    function(ids, opt_userInitiated) {
<a name="line561"></a>  var uniqueIds = [];
<a name="line562"></a>  goog.array.removeDuplicates(ids, uniqueIds);
<a name="line563"></a>  var idsToLoad = [];
<a name="line564"></a>  var deferredMap = {};
<a name="line565"></a>  for (var i = 0; i &lt; uniqueIds.length; i++) {
<a name="line566"></a>    var id = uniqueIds[i];
<a name="line567"></a>    var moduleInfo = this.getModuleInfo(id);
<a name="line568"></a>    if (!moduleInfo) {
<a name="line569"></a>      throw new Error(&#39;Unknown module: &#39; + id);
<a name="line570"></a>    }
<a name="line571"></a>    var d = new goog.async.Deferred();
<a name="line572"></a>    deferredMap[id] = d;
<a name="line573"></a>    if (moduleInfo.isLoaded()) {
<a name="line574"></a>      d.callback(this.moduleContext_);
<a name="line575"></a>    } else {
<a name="line576"></a>      this.registerModuleLoadCallbacks_(id, moduleInfo, !!opt_userInitiated, d);
<a name="line577"></a>      if (!this.isModuleLoading(id)) {
<a name="line578"></a>        idsToLoad.push(id);
<a name="line579"></a>      }
<a name="line580"></a>    }
<a name="line581"></a>  }
<a name="line582"></a>
<a name="line583"></a>  // If there are ids to load, load them, otherwise, they are all loading or
<a name="line584"></a>  // loaded.
<a name="line585"></a>  if (idsToLoad.length &gt; 0) {
<a name="line586"></a>    this.loadModulesOrEnqueue_(idsToLoad);
<a name="line587"></a>  }
<a name="line588"></a>  return deferredMap;
<a name="line589"></a>};
<a name="line590"></a>
<a name="line591"></a>
<a name="line592"></a>/**
<a name="line593"></a> * Registers the callbacks and handles logic if it is a user initiated module
<a name="line594"></a> * load.
<a name="line595"></a> *
<a name="line596"></a> * @param {string} id The id of the module to possibly load.
<a name="line597"></a> * @param {!goog.module.ModuleInfo} moduleInfo The module identifier for the
<a name="line598"></a> *     given id.
<a name="line599"></a> * @param {boolean} userInitiated If the load was user initiated.
<a name="line600"></a> * @param {goog.async.Deferred} d A deferred object.
<a name="line601"></a> * @private
<a name="line602"></a> */
<a name="line603"></a>goog.module.ModuleManager.prototype.registerModuleLoadCallbacks_ =
<a name="line604"></a>    function(id, moduleInfo, userInitiated, d) {
<a name="line605"></a>  moduleInfo.registerCallback(d.callback, d);
<a name="line606"></a>  moduleInfo.registerErrback(function(err) { d.errback(Error(err)); });
<a name="line607"></a>  // If it&#39;s already loading, we don&#39;t have to do anything besides handle
<a name="line608"></a>  // if it was user initiated
<a name="line609"></a>  if (this.isModuleLoading(id)) {
<a name="line610"></a>    if (userInitiated) {
<a name="line611"></a>      goog.log.info(this.logger_,
<a name="line612"></a>          &#39;User initiated module already loading: &#39; + id);
<a name="line613"></a>      this.addUserInitiatedLoadingModule_(id);
<a name="line614"></a>      this.dispatchActiveIdleChangeIfNeeded_();
<a name="line615"></a>    }
<a name="line616"></a>  } else {
<a name="line617"></a>    if (userInitiated) {
<a name="line618"></a>      goog.log.info(this.logger_, &#39;User initiated module load: &#39; + id);
<a name="line619"></a>      this.addUserInitiatedLoadingModule_(id);
<a name="line620"></a>    } else {
<a name="line621"></a>      goog.log.info(this.logger_, &#39;Initiating module load: &#39; + id);
<a name="line622"></a>    }
<a name="line623"></a>  }
<a name="line624"></a>};
<a name="line625"></a>
<a name="line626"></a>
<a name="line627"></a>/**
<a name="line628"></a> * Initiates loading of a list of modules or, if a module is currently being
<a name="line629"></a> * loaded, appends the modules to the queue of requested module ids.
<a name="line630"></a> *
<a name="line631"></a> * The caller should verify that the requested modules are not already loaded or
<a name="line632"></a> * loading. {@link #loadModulesOrEnqueueIfNotLoadedOrLoading_} is a more lenient
<a name="line633"></a> * alternative to this method.
<a name="line634"></a> *
<a name="line635"></a> * @param {Array.&lt;string&gt;} ids The ids of the modules to load.
<a name="line636"></a> * @private
<a name="line637"></a> */
<a name="line638"></a>goog.module.ModuleManager.prototype.loadModulesOrEnqueue_ = function(ids) {
<a name="line639"></a>  // With concurrent loading we always just send off the request.
<a name="line640"></a>  if (this.concurrentLoadingEnabled_) {
<a name="line641"></a>    // For now we wait for initial modules to have downloaded as this puts the
<a name="line642"></a>    // loader in a good state for calculating the needed deps of additional
<a name="line643"></a>    // loads.
<a name="line644"></a>    // TODO(user): Make this wait unnecessary.
<a name="line645"></a>    this.initialModulesLoaded_.addCallback(
<a name="line646"></a>        goog.bind(this.loadModules_, this, ids));
<a name="line647"></a>  } else {
<a name="line648"></a>    if (goog.array.isEmpty(this.loadingModuleIds_)) {
<a name="line649"></a>      this.loadModules_(ids);
<a name="line650"></a>    } else {
<a name="line651"></a>      this.requestedModuleIdsQueue_.push(ids);
<a name="line652"></a>      this.dispatchActiveIdleChangeIfNeeded_();
<a name="line653"></a>    }
<a name="line654"></a>  }
<a name="line655"></a>};
<a name="line656"></a>
<a name="line657"></a>
<a name="line658"></a>/**
<a name="line659"></a> * Gets the amount of delay to wait before sending a request for more modules.
<a name="line660"></a> * If a certain module request fails, we backoff a little bit and try again.
<a name="line661"></a> * @return {number} Delay, in ms.
<a name="line662"></a> * @private
<a name="line663"></a> */
<a name="line664"></a>goog.module.ModuleManager.prototype.getBackOff_ = function() {
<a name="line665"></a>  // 5 seconds after one error, 20 seconds after 2.
<a name="line666"></a>  return Math.pow(this.consecutiveFailures_, 2) * 5000;
<a name="line667"></a>};
<a name="line668"></a>
<a name="line669"></a>
<a name="line670"></a>/**
<a name="line671"></a> * Loads a list of modules and any of their not-yet-loaded prerequisites.
<a name="line672"></a> * If batch mode is enabled, the prerequisites will be loaded together with the
<a name="line673"></a> * requested modules and all requested modules will be loaded at the same time.
<a name="line674"></a> *
<a name="line675"></a> * The caller should verify that the requested modules are not already loaded
<a name="line676"></a> * and that no modules are currently loading before calling this method.
<a name="line677"></a> *
<a name="line678"></a> * @param {Array.&lt;string&gt;} ids The ids of the modules to load.
<a name="line679"></a> * @param {boolean=} opt_isRetry If the load is a retry of a previous load
<a name="line680"></a> *     attempt.
<a name="line681"></a> * @param {boolean=} opt_forceReload Whether to bypass cache while loading the
<a name="line682"></a> *     module.
<a name="line683"></a> * @private
<a name="line684"></a> */
<a name="line685"></a>goog.module.ModuleManager.prototype.loadModules_ = function(
<a name="line686"></a>    ids, opt_isRetry, opt_forceReload) {
<a name="line687"></a>  if (!opt_isRetry) {
<a name="line688"></a>    this.consecutiveFailures_ = 0;
<a name="line689"></a>  }
<a name="line690"></a>
<a name="line691"></a>  // Not all modules may be loaded immediately if batch mode is not enabled.
<a name="line692"></a>  var idsToLoadImmediately = this.processModulesForLoad_(ids);
<a name="line693"></a>
<a name="line694"></a>  goog.log.info(this.logger_, &#39;Loading module(s): &#39; + idsToLoadImmediately);
<a name="line695"></a>  this.loadingModuleIds_ = idsToLoadImmediately;
<a name="line696"></a>
<a name="line697"></a>  if (this.batchModeEnabled_) {
<a name="line698"></a>    this.requestedLoadingModuleIds_ = ids;
<a name="line699"></a>  } else {
<a name="line700"></a>    // If batch mode is disabled, we treat each dependency load as a separate
<a name="line701"></a>    // load.
<a name="line702"></a>    this.requestedLoadingModuleIds_ = goog.array.clone(idsToLoadImmediately);
<a name="line703"></a>  }
<a name="line704"></a>
<a name="line705"></a>  // Dispatch an active/idle change if needed.
<a name="line706"></a>  this.dispatchActiveIdleChangeIfNeeded_();
<a name="line707"></a>
<a name="line708"></a>  if (goog.array.isEmpty(idsToLoadImmediately)) {
<a name="line709"></a>    // All requested modules and deps have been either loaded already or have
<a name="line710"></a>    // already been requested.
<a name="line711"></a>    return;
<a name="line712"></a>  }
<a name="line713"></a>
<a name="line714"></a>  this.requestedModuleIds_.push.apply(this.requestedModuleIds_,
<a name="line715"></a>      idsToLoadImmediately);
<a name="line716"></a>
<a name="line717"></a>  var loadFn = goog.bind(this.loader_.loadModules, this.loader_,
<a name="line718"></a>      goog.array.clone(idsToLoadImmediately),
<a name="line719"></a>      this.moduleInfoMap_,
<a name="line720"></a>      null,
<a name="line721"></a>      goog.bind(this.handleLoadError_, this, this.requestedLoadingModuleIds_,
<a name="line722"></a>          idsToLoadImmediately),
<a name="line723"></a>      goog.bind(this.handleLoadTimeout_, this),
<a name="line724"></a>      !!opt_forceReload);
<a name="line725"></a>
<a name="line726"></a>  var delay = this.getBackOff_();
<a name="line727"></a>  if (delay) {
<a name="line728"></a>    window.setTimeout(loadFn, delay);
<a name="line729"></a>  } else {
<a name="line730"></a>    loadFn();
<a name="line731"></a>  }
<a name="line732"></a>};
<a name="line733"></a>
<a name="line734"></a>
<a name="line735"></a>/**
<a name="line736"></a> * Processes a list of module ids for loading. Checks if any of the modules are
<a name="line737"></a> * already loaded and then gets transitive deps. Queues any necessary modules
<a name="line738"></a> * if batch mode is not enabled. Returns the list of ids that should be loaded.
<a name="line739"></a> *
<a name="line740"></a> * @param {Array.&lt;string&gt;} ids The ids that need to be loaded.
<a name="line741"></a> * @return {!Array.&lt;string&gt;} The ids to load, including dependencies.
<a name="line742"></a> * @throws {Error} If the module is already loaded.
<a name="line743"></a> * @private
<a name="line744"></a> */
<a name="line745"></a>goog.module.ModuleManager.prototype.processModulesForLoad_ = function(ids) {
<a name="line746"></a>  for (var i = 0; i &lt; ids.length; i++) {
<a name="line747"></a>    var moduleInfo = this.moduleInfoMap_[ids[i]];
<a name="line748"></a>    if (moduleInfo.isLoaded()) {
<a name="line749"></a>      throw Error(&#39;Module already loaded: &#39; + ids[i]);
<a name="line750"></a>    }
<a name="line751"></a>  }
<a name="line752"></a>
<a name="line753"></a>  // Build a list of the ids of this module and any of its not-yet-loaded
<a name="line754"></a>  // prerequisite modules in dependency order.
<a name="line755"></a>  var idsWithDeps = [];
<a name="line756"></a>  for (var i = 0; i &lt; ids.length; i++) {
<a name="line757"></a>    idsWithDeps = idsWithDeps.concat(
<a name="line758"></a>        this.getNotYetLoadedTransitiveDepIds_(ids[i]));
<a name="line759"></a>  }
<a name="line760"></a>  goog.array.removeDuplicates(idsWithDeps);
<a name="line761"></a>
<a name="line762"></a>  if (!this.batchModeEnabled_ &amp;&amp; idsWithDeps.length &gt; 1) {
<a name="line763"></a>    var idToLoad = idsWithDeps.shift();
<a name="line764"></a>    goog.log.info(this.logger_,
<a name="line765"></a>        &#39;Must load &#39; + idToLoad + &#39; module before &#39; + ids);
<a name="line766"></a>
<a name="line767"></a>    // Insert the requested module id and any other not-yet-loaded prereqs
<a name="line768"></a>    // that it has at the front of the queue.
<a name="line769"></a>    var queuedModules = goog.array.map(idsWithDeps, function(id) {
<a name="line770"></a>      return [id];
<a name="line771"></a>    });
<a name="line772"></a>    this.requestedModuleIdsQueue_ = queuedModules.concat(
<a name="line773"></a>        this.requestedModuleIdsQueue_);
<a name="line774"></a>    return [idToLoad];
<a name="line775"></a>  } else {
<a name="line776"></a>    return idsWithDeps;
<a name="line777"></a>  }
<a name="line778"></a>};
<a name="line779"></a>
<a name="line780"></a>
<a name="line781"></a>/**
<a name="line782"></a> * Builds a list of the ids of the not-yet-loaded modules that a particular
<a name="line783"></a> * module transitively depends on, including itself.
<a name="line784"></a> *
<a name="line785"></a> * @param {string} id The id of a not-yet-loaded module.
<a name="line786"></a> * @return {!Array.&lt;string&gt;} An array of module ids in dependency order that&#39;s
<a name="line787"></a> *     guaranteed to end with the provided module id.
<a name="line788"></a> * @private
<a name="line789"></a> */
<a name="line790"></a>goog.module.ModuleManager.prototype.getNotYetLoadedTransitiveDepIds_ =
<a name="line791"></a>    function(id) {
<a name="line792"></a>  // NOTE(user): We want the earliest occurrance of a module, not the first
<a name="line793"></a>  // dependency we find. Therefore we strip duplicates at the end rather than
<a name="line794"></a>  // during.  See the tests for concrete examples.
<a name="line795"></a>  var ids = [];
<a name="line796"></a>  if (!goog.array.contains(this.requestedModuleIds_, id)) {
<a name="line797"></a>    ids.push(id);
<a name="line798"></a>  }
<a name="line799"></a>  var depIds = goog.array.clone(this.getModuleInfo(id).getDependencies());
<a name="line800"></a>  while (depIds.length) {
<a name="line801"></a>    var depId = depIds.pop();
<a name="line802"></a>    if (!this.getModuleInfo(depId).isLoaded() &amp;&amp;
<a name="line803"></a>        !goog.array.contains(this.requestedModuleIds_, depId)) {
<a name="line804"></a>      ids.unshift(depId);
<a name="line805"></a>      // We need to process direct dependencies first.
<a name="line806"></a>      Array.prototype.unshift.apply(depIds,
<a name="line807"></a>          this.getModuleInfo(depId).getDependencies());
<a name="line808"></a>    }
<a name="line809"></a>  }
<a name="line810"></a>  goog.array.removeDuplicates(ids);
<a name="line811"></a>  return ids;
<a name="line812"></a>};
<a name="line813"></a>
<a name="line814"></a>
<a name="line815"></a>/**
<a name="line816"></a> * If we are still loading the base module, consider the load complete.
<a name="line817"></a> * @private
<a name="line818"></a> */
<a name="line819"></a>goog.module.ModuleManager.prototype.maybeFinishBaseLoad_ = function() {
<a name="line820"></a>  if (this.currentlyLoadingModule_ == this.baseModuleInfo_) {
<a name="line821"></a>    this.currentlyLoadingModule_ = null;
<a name="line822"></a>    var error = this.baseModuleInfo_.onLoad(
<a name="line823"></a>        goog.bind(this.getModuleContext, this));
<a name="line824"></a>    if (error) {
<a name="line825"></a>      this.dispatchModuleLoadFailed_(
<a name="line826"></a>          goog.module.ModuleManager.FailureType.INIT_ERROR);
<a name="line827"></a>    }
<a name="line828"></a>
<a name="line829"></a>    this.dispatchActiveIdleChangeIfNeeded_();
<a name="line830"></a>  }
<a name="line831"></a>};
<a name="line832"></a>
<a name="line833"></a>
<a name="line834"></a>/**
<a name="line835"></a> * Records that a module was loaded. Also initiates loading the next module if
<a name="line836"></a> * any module requests are queued. This method is called by code that is
<a name="line837"></a> * generated and appended to each dynamic module&#39;s code at compilation time.
<a name="line838"></a> *
<a name="line839"></a> * @param {string} id A module id.
<a name="line840"></a> */
<a name="line841"></a>goog.module.ModuleManager.prototype.setLoaded = function(id) {
<a name="line842"></a>  if (this.isDisposed()) {
<a name="line843"></a>    goog.log.warning(this.logger_,
<a name="line844"></a>        &#39;Module loaded after module manager was disposed: &#39; + id);
<a name="line845"></a>    return;
<a name="line846"></a>  }
<a name="line847"></a>
<a name="line848"></a>  goog.log.info(this.logger_, &#39;Module loaded: &#39; + id);
<a name="line849"></a>
<a name="line850"></a>  var error = this.moduleInfoMap_[id].onLoad(
<a name="line851"></a>      goog.bind(this.getModuleContext, this));
<a name="line852"></a>  if (error) {
<a name="line853"></a>    this.dispatchModuleLoadFailed_(
<a name="line854"></a>        goog.module.ModuleManager.FailureType.INIT_ERROR);
<a name="line855"></a>  }
<a name="line856"></a>
<a name="line857"></a>  // Remove the module id from the user initiated set if it existed there.
<a name="line858"></a>  goog.array.remove(this.userInitiatedLoadingModuleIds_, id);
<a name="line859"></a>
<a name="line860"></a>  // Remove the module id from the loading modules if it exists there.
<a name="line861"></a>  goog.array.remove(this.loadingModuleIds_, id);
<a name="line862"></a>
<a name="line863"></a>  if (goog.array.isEmpty(this.loadingModuleIds_)) {
<a name="line864"></a>    // No more modules are currently being loaded (e.g. arriving later in the
<a name="line865"></a>    // same HTTP response), so proceed to load the next module in the queue.
<a name="line866"></a>    this.loadNextModules_();
<a name="line867"></a>  }
<a name="line868"></a>
<a name="line869"></a>  if (this.lastInitialModuleId_ &amp;&amp; id == this.lastInitialModuleId_) {
<a name="line870"></a>    if (!this.initialModulesLoaded_.hasFired()) {
<a name="line871"></a>      this.initialModulesLoaded_.callback();
<a name="line872"></a>    }
<a name="line873"></a>  }
<a name="line874"></a>
<a name="line875"></a>  // Dispatch an active/idle change if needed.
<a name="line876"></a>  this.dispatchActiveIdleChangeIfNeeded_();
<a name="line877"></a>};
<a name="line878"></a>
<a name="line879"></a>
<a name="line880"></a>/**
<a name="line881"></a> * Gets whether a module is currently loading or in the queue, waiting to be
<a name="line882"></a> * loaded.
<a name="line883"></a> * @param {string} id A module id.
<a name="line884"></a> * @return {boolean} TRUE iff the module is loading.
<a name="line885"></a> */
<a name="line886"></a>goog.module.ModuleManager.prototype.isModuleLoading = function(id) {
<a name="line887"></a>  if (goog.array.contains(this.loadingModuleIds_, id)) {
<a name="line888"></a>    return true;
<a name="line889"></a>  }
<a name="line890"></a>  for (var i = 0; i &lt; this.requestedModuleIdsQueue_.length; i++) {
<a name="line891"></a>    if (goog.array.contains(this.requestedModuleIdsQueue_[i], id)) {
<a name="line892"></a>      return true;
<a name="line893"></a>    }
<a name="line894"></a>  }
<a name="line895"></a>  return false;
<a name="line896"></a>};
<a name="line897"></a>
<a name="line898"></a>
<a name="line899"></a>/**
<a name="line900"></a> * Requests that a function be called once a particular module is loaded.
<a name="line901"></a> * Client code can use this method to safely call into modules that may not yet
<a name="line902"></a> * be loaded. For consistency, this method always calls the function
<a name="line903"></a> * asynchronously -- even if the module is already loaded. Initiates loading of
<a name="line904"></a> * the module if necessary, unless opt_noLoad is true.
<a name="line905"></a> *
<a name="line906"></a> * @param {string} moduleId A module id.
<a name="line907"></a> * @param {Function} fn Function to execute when the module has loaded.
<a name="line908"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line909"></a> *     the callback.
<a name="line910"></a> * @param {boolean=} opt_noLoad TRUE iff not to initiate loading of the module.
<a name="line911"></a> * @param {boolean=} opt_userInitiated TRUE iff the loading of the module was
<a name="line912"></a> *     user initiated.
<a name="line913"></a> * @param {boolean=} opt_preferSynchronous TRUE iff the function should be
<a name="line914"></a> *     executed synchronously if the module has already been loaded.
<a name="line915"></a> * @return {goog.module.ModuleLoadCallback} A callback wrapper that exposes
<a name="line916"></a> *     an abort and execute method.
<a name="line917"></a> */
<a name="line918"></a>goog.module.ModuleManager.prototype.execOnLoad = function(
<a name="line919"></a>    moduleId, fn, opt_handler, opt_noLoad,
<a name="line920"></a>    opt_userInitiated, opt_preferSynchronous) {
<a name="line921"></a>  var moduleInfo = this.moduleInfoMap_[moduleId];
<a name="line922"></a>  var callbackWrapper;
<a name="line923"></a>
<a name="line924"></a>  if (moduleInfo.isLoaded()) {
<a name="line925"></a>    goog.log.info(this.logger_, moduleId + &#39; module already loaded&#39;);
<a name="line926"></a>    // Call async so that code paths don&#39;t change between loaded and unloaded
<a name="line927"></a>    // cases.
<a name="line928"></a>    callbackWrapper = new goog.module.ModuleLoadCallback(fn, opt_handler);
<a name="line929"></a>    if (opt_preferSynchronous) {
<a name="line930"></a>      callbackWrapper.execute(this.moduleContext_);
<a name="line931"></a>    } else {
<a name="line932"></a>      window.setTimeout(
<a name="line933"></a>          goog.bind(callbackWrapper.execute, callbackWrapper), 0);
<a name="line934"></a>    }
<a name="line935"></a>  } else if (this.isModuleLoading(moduleId)) {
<a name="line936"></a>    goog.log.info(this.logger_, moduleId + &#39; module already loading&#39;);
<a name="line937"></a>    callbackWrapper = moduleInfo.registerCallback(fn, opt_handler);
<a name="line938"></a>    if (opt_userInitiated) {
<a name="line939"></a>      goog.log.info(this.logger_,
<a name="line940"></a>          &#39;User initiated module already loading: &#39; + moduleId);
<a name="line941"></a>      this.addUserInitiatedLoadingModule_(moduleId);
<a name="line942"></a>      this.dispatchActiveIdleChangeIfNeeded_();
<a name="line943"></a>    }
<a name="line944"></a>  } else {
<a name="line945"></a>    goog.log.info(this.logger_,
<a name="line946"></a>        &#39;Registering callback for module: &#39; + moduleId);
<a name="line947"></a>    callbackWrapper = moduleInfo.registerCallback(fn, opt_handler);
<a name="line948"></a>    if (!opt_noLoad) {
<a name="line949"></a>      if (opt_userInitiated) {
<a name="line950"></a>        goog.log.info(this.logger_, &#39;User initiated module load: &#39; + moduleId);
<a name="line951"></a>        this.addUserInitiatedLoadingModule_(moduleId);
<a name="line952"></a>      }
<a name="line953"></a>      goog.log.info(this.logger_, &#39;Initiating module load: &#39; + moduleId);
<a name="line954"></a>      this.loadModulesOrEnqueue_([moduleId]);
<a name="line955"></a>    }
<a name="line956"></a>  }
<a name="line957"></a>  return callbackWrapper;
<a name="line958"></a>};
<a name="line959"></a>
<a name="line960"></a>
<a name="line961"></a>/**
<a name="line962"></a> * Loads a module, returning a goog.async.Deferred for keeping track of the
<a name="line963"></a> * result.
<a name="line964"></a> *
<a name="line965"></a> * @param {string} moduleId A module id.
<a name="line966"></a> * @param {boolean=} opt_userInitiated If the load is a result of a user action.
<a name="line967"></a> * @return {goog.async.Deferred} A deferred object.
<a name="line968"></a> */
<a name="line969"></a>goog.module.ModuleManager.prototype.load = function(
<a name="line970"></a>    moduleId, opt_userInitiated) {
<a name="line971"></a>  return this.loadModulesOrEnqueueIfNotLoadedOrLoading_(
<a name="line972"></a>      [moduleId], opt_userInitiated)[moduleId];
<a name="line973"></a>};
<a name="line974"></a>
<a name="line975"></a>
<a name="line976"></a>/**
<a name="line977"></a> * Loads a list of modules, returning a goog.async.Deferred for keeping track of
<a name="line978"></a> * the result.
<a name="line979"></a> *
<a name="line980"></a> * @param {Array.&lt;string&gt;} moduleIds A list of module ids.
<a name="line981"></a> * @param {boolean=} opt_userInitiated If the load is a result of a user action.
<a name="line982"></a> * @return {Object.&lt;!goog.async.Deferred&gt;} A mapping from id (String) to
<a name="line983"></a> *     deferred objects that will callback or errback when the load for that
<a name="line984"></a> *     id is finished.
<a name="line985"></a> */
<a name="line986"></a>goog.module.ModuleManager.prototype.loadMultiple = function(
<a name="line987"></a>    moduleIds, opt_userInitiated) {
<a name="line988"></a>  return this.loadModulesOrEnqueueIfNotLoadedOrLoading_(
<a name="line989"></a>      moduleIds, opt_userInitiated);
<a name="line990"></a>};
<a name="line991"></a>
<a name="line992"></a>
<a name="line993"></a>/**
<a name="line994"></a> * Ensures that the module with the given id is listed as a user-initiated
<a name="line995"></a> * module that is being loaded. This method guarantees that a module will never
<a name="line996"></a> * get listed more than once.
<a name="line997"></a> * @param {string} id Identifier of the module.
<a name="line998"></a> * @private
<a name="line999"></a> */
<a name="line1000"></a>goog.module.ModuleManager.prototype.addUserInitiatedLoadingModule_ = function(
<a name="line1001"></a>    id) {
<a name="line1002"></a>  if (!goog.array.contains(this.userInitiatedLoadingModuleIds_, id)) {
<a name="line1003"></a>    this.userInitiatedLoadingModuleIds_.push(id);
<a name="line1004"></a>  }
<a name="line1005"></a>};
<a name="line1006"></a>
<a name="line1007"></a>
<a name="line1008"></a>/**
<a name="line1009"></a> * Method called just before a module code is loaded.
<a name="line1010"></a> * @param {string} id Identifier of the module.
<a name="line1011"></a> */
<a name="line1012"></a>goog.module.ModuleManager.prototype.beforeLoadModuleCode = function(id) {
<a name="line1013"></a>  this.loadTracer_ = goog.debug.Trace.startTracer(&#39;Module Load: &#39; + id,
<a name="line1014"></a>      &#39;Module Load&#39;);
<a name="line1015"></a>  if (this.currentlyLoadingModule_) {
<a name="line1016"></a>    goog.log.error(this.logger_,
<a name="line1017"></a>        &#39;beforeLoadModuleCode called with module &quot;&#39; + id +
<a name="line1018"></a>        &#39;&quot; while module &quot;&#39; +
<a name="line1019"></a>        this.currentlyLoadingModule_.getId() +
<a name="line1020"></a>        &#39;&quot; is loading&#39;);
<a name="line1021"></a>  }
<a name="line1022"></a>  this.currentlyLoadingModule_ = this.getModuleInfo(id);
<a name="line1023"></a>};
<a name="line1024"></a>
<a name="line1025"></a>
<a name="line1026"></a>/**
<a name="line1027"></a> * Method called just after module code is loaded
<a name="line1028"></a> * @param {string} id Identifier of the module.
<a name="line1029"></a> */
<a name="line1030"></a>goog.module.ModuleManager.prototype.afterLoadModuleCode = function(id) {
<a name="line1031"></a>  if (!this.currentlyLoadingModule_ ||
<a name="line1032"></a>      id != this.currentlyLoadingModule_.getId()) {
<a name="line1033"></a>    goog.log.error(this.logger_,
<a name="line1034"></a>        &#39;afterLoadModuleCode called with module &quot;&#39; + id +
<a name="line1035"></a>        &#39;&quot; while loading module &quot;&#39; +
<a name="line1036"></a>        (this.currentlyLoadingModule_ &amp;&amp;
<a name="line1037"></a>        this.currentlyLoadingModule_.getId()) + &#39;&quot;&#39;);
<a name="line1038"></a>
<a name="line1039"></a>  }
<a name="line1040"></a>  this.currentlyLoadingModule_ = null;
<a name="line1041"></a>  goog.debug.Trace.stopTracer(this.loadTracer_);
<a name="line1042"></a>};
<a name="line1043"></a>
<a name="line1044"></a>
<a name="line1045"></a>/**
<a name="line1046"></a> * Register an initialization callback for the currently loading module. This
<a name="line1047"></a> * should only be called by script that is executed during the evaluation of
<a name="line1048"></a> * a module&#39;s javascript. This is almost equivalent to calling the function
<a name="line1049"></a> * inline, but ensures that all the code from the currently loading module
<a name="line1050"></a> * has been loaded. This makes it cleaner and more robust than calling the
<a name="line1051"></a> * function inline.
<a name="line1052"></a> *
<a name="line1053"></a> * If this function is called from the base module (the one that contains
<a name="line1054"></a> * the module manager code), the callback is held until #setAllModuleInfo
<a name="line1055"></a> * is called, or until #setModuleContext is called, whichever happens first.
<a name="line1056"></a> *
<a name="line1057"></a> * @param {Function} fn A callback function that takes a single argument
<a name="line1058"></a> *    which is the module context.
<a name="line1059"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line1060"></a> *     the callback.
<a name="line1061"></a> */
<a name="line1062"></a>goog.module.ModuleManager.prototype.registerInitializationCallback = function(
<a name="line1063"></a>    fn, opt_handler) {
<a name="line1064"></a>  if (!this.currentlyLoadingModule_) {
<a name="line1065"></a>    goog.log.error(this.logger_, &#39;No module is currently loading&#39;);
<a name="line1066"></a>  } else {
<a name="line1067"></a>    this.currentlyLoadingModule_.registerEarlyCallback(fn, opt_handler);
<a name="line1068"></a>  }
<a name="line1069"></a>};
<a name="line1070"></a>
<a name="line1071"></a>
<a name="line1072"></a>/**
<a name="line1073"></a> * Register a late initialization callback for the currently loading module.
<a name="line1074"></a> * Callbacks registered via this function are executed similar to
<a name="line1075"></a> * {@see registerInitializationCallback}, but they are fired after all
<a name="line1076"></a> * initialization callbacks are called.
<a name="line1077"></a> *
<a name="line1078"></a> * @param {Function} fn A callback function that takes a single argument
<a name="line1079"></a> *    which is the module context.
<a name="line1080"></a> * @param {Object=} opt_handler Optional handler under whose scope to execute
<a name="line1081"></a> *     the callback.
<a name="line1082"></a> */
<a name="line1083"></a>goog.module.ModuleManager.prototype.registerLateInitializationCallback =
<a name="line1084"></a>    function(fn, opt_handler) {
<a name="line1085"></a>  if (!this.currentlyLoadingModule_) {
<a name="line1086"></a>    goog.log.error(this.logger_, &#39;No module is currently loading&#39;);
<a name="line1087"></a>  } else {
<a name="line1088"></a>    this.currentlyLoadingModule_.registerCallback(fn, opt_handler);
<a name="line1089"></a>  }
<a name="line1090"></a>};
<a name="line1091"></a>
<a name="line1092"></a>
<a name="line1093"></a>/**
<a name="line1094"></a> * Sets the constructor to use for the module object for the currently
<a name="line1095"></a> * loading module. The constructor should derive from {@see
<a name="line1096"></a> * goog.module.BaseModule}.
<a name="line1097"></a> * @param {Function} fn The constructor function.
<a name="line1098"></a> */
<a name="line1099"></a>goog.module.ModuleManager.prototype.setModuleConstructor = function(fn) {
<a name="line1100"></a>  if (!this.currentlyLoadingModule_) {
<a name="line1101"></a>    goog.log.error(this.logger_, &#39;No module is currently loading&#39;);
<a name="line1102"></a>    return;
<a name="line1103"></a>  }
<a name="line1104"></a>  this.currentlyLoadingModule_.setModuleConstructor(fn);
<a name="line1105"></a>};
<a name="line1106"></a>
<a name="line1107"></a>
<a name="line1108"></a>/**
<a name="line1109"></a> * The possible reasons for a module load failure callback being fired.
<a name="line1110"></a> * @enum {number}
<a name="line1111"></a> */
<a name="line1112"></a>goog.module.ModuleManager.FailureType = {
<a name="line1113"></a>  /** 401 Status. */
<a name="line1114"></a>  UNAUTHORIZED: 0,
<a name="line1115"></a>
<a name="line1116"></a>  /** Error status (not 401) returned multiple times. */
<a name="line1117"></a>  CONSECUTIVE_FAILURES: 1,
<a name="line1118"></a>
<a name="line1119"></a>  /** Request timeout. */
<a name="line1120"></a>  TIMEOUT: 2,
<a name="line1121"></a>
<a name="line1122"></a>  /** 410 status, old code gone. */
<a name="line1123"></a>  OLD_CODE_GONE: 3,
<a name="line1124"></a>
<a name="line1125"></a>  /** The onLoad callbacks failed. */
<a name="line1126"></a>  INIT_ERROR: 4
<a name="line1127"></a>};
<a name="line1128"></a>
<a name="line1129"></a>
<a name="line1130"></a>/**
<a name="line1131"></a> * Handles a module load failure.
<a name="line1132"></a> *
<a name="line1133"></a> * @param {!Array.&lt;string&gt;} requestedLoadingModuleIds Modules ids that were
<a name="line1134"></a> *     requested in failed request. Does not included calculated dependencies.
<a name="line1135"></a> * @param {!Array.&lt;string&gt;} requestedModuleIdsWithDeps All module ids requested
<a name="line1136"></a> *     in the failed request including all dependencies.
<a name="line1137"></a> * @param {?number} status The error status.
<a name="line1138"></a> * @private
<a name="line1139"></a> */
<a name="line1140"></a>goog.module.ModuleManager.prototype.handleLoadError_ = function(
<a name="line1141"></a>    requestedLoadingModuleIds, requestedModuleIdsWithDeps, status) {
<a name="line1142"></a>  this.consecutiveFailures_++;
<a name="line1143"></a>  // Module manager was not designed to be reentrant. Reinstate the instance
<a name="line1144"></a>  // var with actual value when request failed (Other requests may have
<a name="line1145"></a>  // started already.)
<a name="line1146"></a>  this.requestedLoadingModuleIds_ = requestedLoadingModuleIds;
<a name="line1147"></a>  // Pretend we never requested the failed modules.
<a name="line1148"></a>  goog.array.forEach(requestedModuleIdsWithDeps,
<a name="line1149"></a>      goog.partial(goog.array.remove, this.requestedModuleIds_), this);
<a name="line1150"></a>
<a name="line1151"></a>  if (status == 401) {
<a name="line1152"></a>    // The user is not logged in. They&#39;ve cleared their cookies or logged out
<a name="line1153"></a>    // from another window.
<a name="line1154"></a>    goog.log.info(this.logger_, &#39;Module loading unauthorized&#39;);
<a name="line1155"></a>    this.dispatchModuleLoadFailed_(
<a name="line1156"></a>        goog.module.ModuleManager.FailureType.UNAUTHORIZED);
<a name="line1157"></a>    // Drop any additional module requests.
<a name="line1158"></a>    this.requestedModuleIdsQueue_.length = 0;
<a name="line1159"></a>  } else if (status == 410) {
<a name="line1160"></a>    // The requested module js is old and not available.
<a name="line1161"></a>    this.requeueBatchOrDispatchFailure_(
<a name="line1162"></a>        goog.module.ModuleManager.FailureType.OLD_CODE_GONE);
<a name="line1163"></a>    this.loadNextModules_();
<a name="line1164"></a>  } else if (this.consecutiveFailures_ &gt;= 3) {
<a name="line1165"></a>    goog.log.info(this.logger_, &#39;Aborting after failure to load: &#39; +
<a name="line1166"></a>                      this.loadingModuleIds_);
<a name="line1167"></a>    this.requeueBatchOrDispatchFailure_(
<a name="line1168"></a>        goog.module.ModuleManager.FailureType.CONSECUTIVE_FAILURES);
<a name="line1169"></a>    this.loadNextModules_();
<a name="line1170"></a>  } else {
<a name="line1171"></a>    goog.log.info(this.logger_, &#39;Retrying after failure to load: &#39; +
<a name="line1172"></a>                      this.loadingModuleIds_);
<a name="line1173"></a>    var forceReload =
<a name="line1174"></a>        status == goog.module.ModuleManager.CORRUPT_RESPONSE_STATUS_CODE;
<a name="line1175"></a>    this.loadModules_(this.requestedLoadingModuleIds_, true, forceReload);
<a name="line1176"></a>  }
<a name="line1177"></a>};
<a name="line1178"></a>
<a name="line1179"></a>
<a name="line1180"></a>/**
<a name="line1181"></a> * Handles a module load timeout.
<a name="line1182"></a> * @private
<a name="line1183"></a> */
<a name="line1184"></a>goog.module.ModuleManager.prototype.handleLoadTimeout_ = function() {
<a name="line1185"></a>  goog.log.info(this.logger_,
<a name="line1186"></a>      &#39;Aborting after timeout: &#39; + this.loadingModuleIds_);
<a name="line1187"></a>  this.requeueBatchOrDispatchFailure_(
<a name="line1188"></a>      goog.module.ModuleManager.FailureType.TIMEOUT);
<a name="line1189"></a>  this.loadNextModules_();
<a name="line1190"></a>};
<a name="line1191"></a>
<a name="line1192"></a>
<a name="line1193"></a>/**
<a name="line1194"></a> * Requeues batch loads that had more than one requested module
<a name="line1195"></a> * (i.e. modules that were not included as dependencies) as separate loads or
<a name="line1196"></a> * if there was only one requested module, fails that module with the received
<a name="line1197"></a> * cause.
<a name="line1198"></a> * @param {goog.module.ModuleManager.FailureType} cause The reason for the
<a name="line1199"></a> *     failure.
<a name="line1200"></a> * @private
<a name="line1201"></a> */
<a name="line1202"></a>goog.module.ModuleManager.prototype.requeueBatchOrDispatchFailure_ =
<a name="line1203"></a>    function(cause) {
<a name="line1204"></a>  // The load failed, so if there are more than one requested modules, then we
<a name="line1205"></a>  // need to retry each one as a separate load. Otherwise, if there is only one
<a name="line1206"></a>  // requested module, remove it and its dependencies from the queue.
<a name="line1207"></a>  if (this.requestedLoadingModuleIds_.length &gt; 1) {
<a name="line1208"></a>    var queuedModules = goog.array.map(this.requestedLoadingModuleIds_,
<a name="line1209"></a>        function(id) {
<a name="line1210"></a>          return [id];
<a name="line1211"></a>        });
<a name="line1212"></a>    this.requestedModuleIdsQueue_ = queuedModules.concat(
<a name="line1213"></a>        this.requestedModuleIdsQueue_);
<a name="line1214"></a>  } else {
<a name="line1215"></a>    this.dispatchModuleLoadFailed_(cause);
<a name="line1216"></a>  }
<a name="line1217"></a>};
<a name="line1218"></a>
<a name="line1219"></a>
<a name="line1220"></a>/**
<a name="line1221"></a> * Handles when a module load failed.
<a name="line1222"></a> * @param {goog.module.ModuleManager.FailureType} cause The reason for the
<a name="line1223"></a> *     failure.
<a name="line1224"></a> * @private
<a name="line1225"></a> */
<a name="line1226"></a>goog.module.ModuleManager.prototype.dispatchModuleLoadFailed_ = function(
<a name="line1227"></a>    cause) {
<a name="line1228"></a>  var failedIds = this.requestedLoadingModuleIds_;
<a name="line1229"></a>  this.loadingModuleIds_.length = 0;
<a name="line1230"></a>  // If any pending modules depend on the id that failed,
<a name="line1231"></a>  // they need to be removed from the queue.
<a name="line1232"></a>  var idsToCancel = [];
<a name="line1233"></a>  for (var i = 0; i &lt; this.requestedModuleIdsQueue_.length; i++) {
<a name="line1234"></a>    var dependentModules = goog.array.filter(
<a name="line1235"></a>        this.requestedModuleIdsQueue_[i],
<a name="line1236"></a>        /**
<a name="line1237"></a>         * Returns true if the requestedId has dependencies on the modules that
<a name="line1238"></a>         * just failed to load.
<a name="line1239"></a>         * @param {string} requestedId The module to check for dependencies.
<a name="line1240"></a>         * @return {boolean} True if the module depends on failed modules.
<a name="line1241"></a>         */
<a name="line1242"></a>        function(requestedId) {
<a name="line1243"></a>          var requestedDeps = this.getNotYetLoadedTransitiveDepIds_(
<a name="line1244"></a>              requestedId);
<a name="line1245"></a>          return goog.array.some(failedIds, function(id) {
<a name="line1246"></a>            return goog.array.contains(requestedDeps, id);
<a name="line1247"></a>          });
<a name="line1248"></a>        }, this);
<a name="line1249"></a>    goog.array.extend(idsToCancel, dependentModules);
<a name="line1250"></a>  }
<a name="line1251"></a>
<a name="line1252"></a>  // Also insert the ids that failed to load as ids to cancel.
<a name="line1253"></a>  for (var i = 0; i &lt; failedIds.length; i++) {
<a name="line1254"></a>    goog.array.insert(idsToCancel, failedIds[i]);
<a name="line1255"></a>  }
<a name="line1256"></a>
<a name="line1257"></a>  // Remove ids to cancel from the queues.
<a name="line1258"></a>  for (var i = 0; i &lt; idsToCancel.length; i++) {
<a name="line1259"></a>    for (var j = 0; j &lt; this.requestedModuleIdsQueue_.length; j++) {
<a name="line1260"></a>      goog.array.remove(this.requestedModuleIdsQueue_[j], idsToCancel[i]);
<a name="line1261"></a>    }
<a name="line1262"></a>    goog.array.remove(this.userInitiatedLoadingModuleIds_, idsToCancel[i]);
<a name="line1263"></a>  }
<a name="line1264"></a>
<a name="line1265"></a>  // Call the functions for error notification.
<a name="line1266"></a>  var errorCallbacks = this.callbackMap_[
<a name="line1267"></a>      goog.module.ModuleManager.CallbackType.ERROR];
<a name="line1268"></a>  if (errorCallbacks) {
<a name="line1269"></a>    for (var i = 0; i &lt; errorCallbacks.length; i++) {
<a name="line1270"></a>      var callback = errorCallbacks[i];
<a name="line1271"></a>      for (var j = 0; j &lt; idsToCancel.length; j++) {
<a name="line1272"></a>        callback(goog.module.ModuleManager.CallbackType.ERROR, idsToCancel[j],
<a name="line1273"></a>            cause);
<a name="line1274"></a>      }
<a name="line1275"></a>    }
<a name="line1276"></a>  }
<a name="line1277"></a>
<a name="line1278"></a>  // Call the errbacks on the module info.
<a name="line1279"></a>  for (var i = 0; i &lt; failedIds.length; i++) {
<a name="line1280"></a>    if (this.moduleInfoMap_[failedIds[i]]) {
<a name="line1281"></a>      this.moduleInfoMap_[failedIds[i]].onError(cause);
<a name="line1282"></a>    }
<a name="line1283"></a>  }
<a name="line1284"></a>
<a name="line1285"></a>  // Clear the requested loading module ids.
<a name="line1286"></a>  this.requestedLoadingModuleIds_.length = 0;
<a name="line1287"></a>
<a name="line1288"></a>  this.dispatchActiveIdleChangeIfNeeded_();
<a name="line1289"></a>};
<a name="line1290"></a>
<a name="line1291"></a>
<a name="line1292"></a>/**
<a name="line1293"></a> * Loads the next modules on the queue.
<a name="line1294"></a> * @private
<a name="line1295"></a> */
<a name="line1296"></a>goog.module.ModuleManager.prototype.loadNextModules_ = function() {
<a name="line1297"></a>  while (this.requestedModuleIdsQueue_.length) {
<a name="line1298"></a>    // Remove modules that are already loaded.
<a name="line1299"></a>    var nextIds = goog.array.filter(this.requestedModuleIdsQueue_.shift(),
<a name="line1300"></a>        /** @param {string} id The module id. */
<a name="line1301"></a>        function(id) {
<a name="line1302"></a>          return !this.getModuleInfo(id).isLoaded();
<a name="line1303"></a>        }, this);
<a name="line1304"></a>    if (nextIds.length &gt; 0) {
<a name="line1305"></a>      this.loadModules_(nextIds);
<a name="line1306"></a>      return;
<a name="line1307"></a>    }
<a name="line1308"></a>  }
<a name="line1309"></a>
<a name="line1310"></a>  // Dispatch an active/idle change if needed.
<a name="line1311"></a>  this.dispatchActiveIdleChangeIfNeeded_();
<a name="line1312"></a>};
<a name="line1313"></a>
<a name="line1314"></a>
<a name="line1315"></a>/**
<a name="line1316"></a> * The function to call if the module manager is in error.
<a name="line1317"></a> * @param {goog.module.ModuleManager.CallbackType|Array.&lt;goog.module.ModuleManager.CallbackType&gt;} types
<a name="line1318"></a> *  The callback type.
<a name="line1319"></a> * @param {Function} fn The function to register as a callback.
<a name="line1320"></a> */
<a name="line1321"></a>goog.module.ModuleManager.prototype.registerCallback = function(
<a name="line1322"></a>    types, fn) {
<a name="line1323"></a>  if (!goog.isArray(types)) {
<a name="line1324"></a>    types = [types];
<a name="line1325"></a>  }
<a name="line1326"></a>
<a name="line1327"></a>  for (var i = 0; i &lt; types.length; i++) {
<a name="line1328"></a>    this.registerCallback_(types[i], fn);
<a name="line1329"></a>  }
<a name="line1330"></a>};
<a name="line1331"></a>
<a name="line1332"></a>
<a name="line1333"></a>/**
<a name="line1334"></a> * Register a callback for the specified callback type.
<a name="line1335"></a> * @param {goog.module.ModuleManager.CallbackType} type The callback type.
<a name="line1336"></a> * @param {Function} fn The callback function.
<a name="line1337"></a> * @private
<a name="line1338"></a> */
<a name="line1339"></a>goog.module.ModuleManager.prototype.registerCallback_ = function(type, fn) {
<a name="line1340"></a>  var callbackMap = this.callbackMap_;
<a name="line1341"></a>  if (!callbackMap[type]) {
<a name="line1342"></a>    callbackMap[type] = [];
<a name="line1343"></a>  }
<a name="line1344"></a>  callbackMap[type].push(fn);
<a name="line1345"></a>};
<a name="line1346"></a>
<a name="line1347"></a>
<a name="line1348"></a>/**
<a name="line1349"></a> * Call the callback functions of the specified type.
<a name="line1350"></a> * @param {goog.module.ModuleManager.CallbackType} type The callback type.
<a name="line1351"></a> * @private
<a name="line1352"></a> */
<a name="line1353"></a>goog.module.ModuleManager.prototype.executeCallbacks_ = function(type) {
<a name="line1354"></a>  var callbacks = this.callbackMap_[type];
<a name="line1355"></a>  for (var i = 0; callbacks &amp;&amp; i &lt; callbacks.length; i++) {
<a name="line1356"></a>    callbacks[i](type);
<a name="line1357"></a>  }
<a name="line1358"></a>};
<a name="line1359"></a>
<a name="line1360"></a>
<a name="line1361"></a>/** @override */
<a name="line1362"></a>goog.module.ModuleManager.prototype.disposeInternal = function() {
<a name="line1363"></a>  goog.module.ModuleManager.superClass_.disposeInternal.call(this);
<a name="line1364"></a>
<a name="line1365"></a>  // Dispose of each ModuleInfo object.
<a name="line1366"></a>  goog.disposeAll(
<a name="line1367"></a>      goog.object.getValues(this.moduleInfoMap_), this.baseModuleInfo_);
<a name="line1368"></a>  this.moduleInfoMap_ = null;
<a name="line1369"></a>  this.loadingModuleIds_ = null;
<a name="line1370"></a>  this.requestedLoadingModuleIds_ = null;
<a name="line1371"></a>  this.userInitiatedLoadingModuleIds_ = null;
<a name="line1372"></a>  this.requestedModuleIdsQueue_ = null;
<a name="line1373"></a>  this.callbackMap_ = null;
<a name="line1374"></a>};
</pre>


</body>
</html>
